<template>
  <div>
    <el-dialog
      :title="title"
      :visible.sync="dialogVisible"
      width="60%"
      :before-close="handleClose"
    >
      <taskform ref="taskform" />
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="submit">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import taskform from "./taskform.vue";
export default {
  components: {
    taskform,
  },
  data() {
    return {
      dialogVisible: false,
      title: "",
    };
  },
  mounted() {},
  methods: {
    handleClose() {
      this.dialogVisible = false;
    },
    submit() {
      if (this.title == "新增任务") {
        let obj = {
          type: "add",
          dept: this.$store.state.user.info.dept,
        };
        obj = Object.assign(obj, this.$refs.taskform.form);
        this.$refs.taskform.$refs.form.validate((valid) => {
          if (valid) {
            this.$http.post("/postTask", obj).then((res) => {
              if (res.code == 200) {
                this.$message.success("新增成功");
                this.$nextTick(() => {
                  this.dialogVisible = false;
                  this.clear();
                });
              }
            });
          }
        });
      }
    },
    clear() {
      for (let keys in this.$refs.taskform.form) {
        this.$refs.taskform.form[keys] = "";
      }
    },
  },
};
</script>

<style>
</style>